// pages/offLine/offLine.js
import validate from '../../../utils/validate.js'
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userid:'',
    username:'',
    cardid:'',
    status:'',
    statusValue:'',
    storeid:'',
    storename:'',
    scheList:[]

    
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options.user)
    let user = JSON.parse(options.user);
    this.setData({
      userid:user.userid,
      username:user.username,
      cardid:user.cardid,
      status:user.status,
      statusValue:user.statusValue,
      storename:user.storename,
      storeid:user.storeid,
      scheList:user.schedulelist
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  shenhe:function(){
    if(validate.validatenull(this.data.storeid)){
      app.dialog.waring('请选择店铺');
      return;
    }
    let data = {userid:this.data.userid,status:1,storeid:this.data.storeid}
    app.api.saveMyOffLine(data).then(res=>{
      app.dialog.success(res.info)
      wx.navigateBack()
    })
  },
  reject:function(){
    if(validate.validatenull(this.data.storeid)){
      app.dialog.waring('请选择店铺');
      return;
    }
    let data = {userid:this.data.userid,status:3,storeid:this.data.storeid}
    app.api.saveMyOffLine(data).then(res=>{
      app.dialog.success(res.info)
      wx.navigateBack()
    })
  },
  cancel:function(){
    if(validate.validatenull(this.data.storeid)){
      app.dialog.waring('请选择店铺');
      return;
    }
    let data = {userid:this.data.userid,status:0,storeid:this.data.storeid}
    app.api.saveMyOffLine(data).then(res=>{
      app.dialog.success(res.info)
      wx.navigateBack()
    })
  },
  clickShop:function(){
    if(this.data.status == 2){
      return;
    }
    wx.navigateTo({
      url: '../shopList/shopList',
    })
  },
  selUser:function(user){
    this.setData({
      storeid:user.storeid,
      storename:user.storename
    })
  }
})